package com.mingmen.supplier.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.CancelModel;

import java.util.ArrayList;
import java.util.List;


public class CancelShopDetailAdapter extends RecyclerView.Adapter<CancelShopDetailAdapter.ViewHolder> {
    List<CancelModel.DataBean.BillDetailsBean> myLiveList = new ArrayList<>();
    Context mContext;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition = -1;

    //recycleview标签
    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<CancelModel.DataBean.BillDetailsBean> myLiveList);
    }


    public CancelShopDetailAdapter(Context context, List<CancelModel.DataBean.BillDetailsBean> myLiveList) {
        this.mContext = context;
        this.myLiveList = myLiveList;

    }

    public void setDataList(List<CancelModel.DataBean.BillDetailsBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cancelshop, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        CancelModel.DataBean.BillDetailsBean billDetailsBean = myLiveList.get(position);

        holder.commodityName.setText(billDetailsBean.getCommodityName());
        Glide.with(mContext).load(AppConfig.IMGURL + billDetailsBean.getPicture()).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(holder.picture);
        holder.spec.setText("规格" + billDetailsBean.getSpec());
        holder.describe.setText(billDetailsBean.getDescribe());
        holder.applyPrice.setText(billDetailsBean.getApplyPrice()+"元");
        holder.arrivePrice.setText(billDetailsBean.getArrivePrice()+"元");
        holder.arriveAmount.setText(billDetailsBean.getArriveAmount()+"个");
        holder.text_total.setText(billDetailsBean.getArriveTotal()+"元");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });

    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {


        LinearLayout content;
        TextView commodityName;
        ImageView picture;
        TextView spec;
        TextView describe;
        TextView applyPrice;
        TextView arrivePrice;
        TextView arriveAmount;
        TextView text_total;

        public ViewHolder(View itemView) {
            super(itemView);

            spec = itemView.findViewById(R.id.spec);
            content = itemView.findViewById(R.id.content);
            commodityName = itemView.findViewById(R.id.commodityName);
            picture = itemView.findViewById(R.id.picture);
            describe = itemView.findViewById(R.id.describe);
            applyPrice = itemView.findViewById(R.id.applyPrice);
            arrivePrice = itemView.findViewById(R.id.arrivePrice);
            arriveAmount = itemView.findViewById(R.id.arriveAmount);
            text_total= itemView.findViewById(R.id.text_total);
        }
    }


}
